package com.china.zhuoyue.ui.activity.login

import android.view.View
import androidx.lifecycle.lifecycleScope
import com.china.zhuoyue.R
import com.china.zhuoyue.databinding.ActivityEmptyBinding
import com.china.zhuoyue.ui.base.BaseActivity
import com.china.zhuoyue.ui.dialog.SecretDialog
import com.china.zhuoyue.ui.ext.startActivityExt
import com.china.zhuoyue.ui.utils.SPUtils
import kotlinx.coroutines.delay
import me.jessyan.autosize.internal.CancelAdapt

class SplashActivity : BaseActivity<ActivityEmptyBinding>(), CancelAdapt {
    override fun initData() {
        if (!SPUtils.getBoolean("sp_key_secret", false)) {
            val secretDialog = SecretDialog(this)
            secretDialog.setOnClickListener(::onViewClicked)
            secretDialog.show()
        } else {
            lifecycleScope.launchWhenStarted {
                delay(2000)
                goMain()
            }
        }
    }

    private fun onViewClicked(view: View) {
        when (view.id) {
            R.id.btn_cancel -> finish()
            R.id.btn_confirm -> {
                SPUtils.put("sp_key_secret", true)
                goMain()
            }
        }
    }

    private fun goMain() {
        startActivityExt<LoginActivity>()
        finish()
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out)
    }
}